const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = [{
    mode: 'development',
    context: __dirname,
    entry: {
        app: './src/index.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    devtool: 'eval',
    amd:{
        toUrlUndefined: true
    },
    node: {
        // Resolve node module use of fs
        fs: "empty",
        Buffer: false,
        http: "empty",
        https: "empty",
        zlib: "empty"
    },
    resolve: {
        mainFields: ['module', 'main']
    },
    module: {
        unknownContextCritical: false,
        rules: [{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        }, 
        // {
        //     test:/\.js$/,
        //     exclude:/(node_modules|bower_components)/,//排除掉node_module目录
        //     use:{
        //         loader:'babel-loader',
        //         options:{
        //             presets:['@babel/env'], //转码规则
        //             // plugins:['transform-runtime']
        //         }
        //     }
        // },
        {
            test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
            use: ['url-loader']
          },{
            test: /\.(png|gif|jpg|jpeg|svg|xml)$/,
            use: ['url-loader']
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html'
        }),
        // Copy Cesium Assets, Widgets, and Workers to a static directory
        new CopyWebpackPlugin([{ from: 'node_modules/cesium/Build/Cesium/Workers', to: 'Workers' }]),
        new CopyWebpackPlugin([{ from: 'node_modules/cesium/Build/Cesium/ThirdParty', to: 'ThirdParty' }]),
        new CopyWebpackPlugin([{ from: 'node_modules/cesium/Build/Cesium/Assets', to: 'Assets' }]),
        new CopyWebpackPlugin([{ from: 'node_modules/cesium/Build/Cesium/Widgets', to: 'Widgets' }]),
        new webpack.DefinePlugin({
            // Define relative base path in cesium for loading assets
            CESIUM_BASE_URL: JSON.stringify('./')
        }),
        new webpack.ProvidePlugin({
            $:"jquery",
            jQuery:"jquery",
            "window.jQuery":"jquery"
        })
    ],

    // development server options
    devServer: {
        contentBase: path.join(__dirname, "dist"),
        open: true,  // 自动打开浏览器
        port: 8089, // 端口号
        hot:true,  //热更新
    }
}];